/*
 * main.c : test demo driver
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "pwm_music.h"

#include "driver/fs4412_pwm.h"

int main()
{
	int i = 0;
	int n = 2;
	int dev_fd;
	int div;
	//int pre = 199;
	dev_fd = open("/dev/pwm",O_RDWR | O_NONBLOCK);
	if ( dev_fd == -1 ) {
		perror("open");
		exit(1);
	}
	//打开pwm定时器,调用函数int ioctl(int fd,int cmd),cmd为PWM_ON; 
	ioctl(dev_fd,PWM_ON);
	while (1)
	{
		for(i = 0;i<sizeof(MotherLoveMeOnceAgain)/sizeof(Note);i++ )
		{
			div = (PCLK/256/4)/(MotherLoveMeOnceAgain[i].pitch);
		 //调用函数int ioctl(int fd,int cmd,char *argp)设置pwm定时器的初值和翻转值，cmd为SET_CNT，把div传入第三个参数;
             //请同学们完成
                        ioctl(dev_fd,SET_CNT,&div);
			usleep(MotherLoveMeOnceAgain[i].dimation * 100);
		}
	}

#if 0
	for(i = 0;i<sizeof(DaeJangGeum)/sizeof(Note);i++ )
	{
		div = (PCLK/256/4)/(DaeJangGeum[i].pitch);
	 //调用函数int ioctl(int fd,int cmd,char *argp)设置pwm定时器的初值和翻转值，cmd为SET_CNT，把div传入第三个参数;
             //请同学们完成
		usleep(DaeJangGeum[i].dimation * 50); 
	}

	for(i = 0;i<sizeof(FishBoat)/sizeof(Note);i++ )
	{
		div = (PCLK/256/4)/(FishBoat[i].pitch);
		 //调用函数int ioctl(int fd,int cmd,char *argp)设置pwm定时器的初值和翻转值，cmd为SET_CNT，把div传入第三个参数;
             //请同学们完成
		usleep(FishBoat[i].dimation * 50); 
	}
#endif
	return 0;
}
